package business.impl;

import java.util.List;

import org.springframework.stereotype.Component;
import model.TLine;
import business.basic.iHibBaseDAO;
import business.basic.iHibBaseDAOImpl;
import business.dao.LineDAO;

@Component("linedao")
public class LineDAOImpl implements LineDAO {
	
	private iHibBaseDAO bdao = null;

	public LineDAOImpl() {
		bdao = new iHibBaseDAOImpl();
	}

	public void setBdao(iHibBaseDAO bdao) {
		this.bdao = bdao;
	}
	
	@Override
	public int add(TLine line) {
		Object obj = bdao.insert(line);
		if(obj!=null){
			return Integer.parseInt(obj.toString());
		}
		return 0;
	}

	@Override
	public boolean update(TLine line) {
		return bdao.update(line);
	}

	@Override
	public boolean delete(int lineid) {
		return bdao.delete(TLine.class, lineid);
	}

	@Override
	public TLine getLineId(int lineid) {
		return (TLine)bdao.findById(TLine.class, lineid);
	}

	@Override
	public List<TLine> getLine() {
		String hql = "from TLine";
		return bdao.select(hql);
	}

	@Override
	public List<TLine> getTlineByWhere(String wherecondition, int startPage,
			int pageSize) {
		String hql = "from TLine";
		if(wherecondition!=null && !wherecondition.equals("")){
			hql += wherecondition;
		}
		return bdao.selectByPage(hql, startPage, pageSize);
	}

	@Override
	public int getAmounTlineByWhere(String wherecondition) {
		String hql = "select count(*) from TLine ";
		if (wherecondition != null && !wherecondition.equals("")) {
			hql += wherecondition;
		}
		return bdao.selectValue(hql);
	}

}
